<template>
	<view class="content" style="padding-top: 0upx;">

        <!-- #ifdef MP-WEIXIN -->
        <view class="subscription-notice" v-if="suTip">
            <view>
                <image class="icon" src="/static/image/subscription-tip.png" mode=""></image>
                <text>订阅消息，及时获取订单最新动态</text>
            </view>
            <view>
                <text class="subscription-notice-btn red-price" @click="toSubscription()">消息订阅</text>
                <text class="subscription-notice-btn-close" @click="toClose()">×</text>
            </view>
        </view>
        <!-- #endif -->

		<jshop :jdata="pageData"></jshop>

		<!-- #ifdef H5 || APP-PLUS-NVUE || APP-PLUS -->
		<view class="service" @click="showChat()"><image class="icon" src="/static/image/seller-content.png" mode=""></image></view>
		<!-- #endif -->
		<!-- #ifdef MP-WEIXIN -->
		<button class="service" hover-class="none" open-type="contact" bindcontact="showChat" :session-from="kefupara">
			<image class="icon" src="/static/image/seller-content.png" mode=""></image>
		</button>
		<!-- #endif -->
		<!-- #ifdef MP-ALIPAY -->
		<contact-button class="service icon" icon="/static/image/seller-content.png" size="80rpx*80rpx" tnt-inst-id="WKPKUZXG" scene="SCE00040186" hover-class="none" />
		<!-- #endif -->
		<!-- #ifdef MP-TOUTIAO -->
		<!-- 头条客服 -->
		<!-- #endif -->
		<red-bag v-if="redBagShow" @click="handleGet"></red-bag>

	</view>
</template>
<script>
import mallplusCopyright from '@/components/mall-copyright/mallplusCopyright.vue';
import Api from '@/common/api';
import jshop from '@/components/jshop/jshop.vue';

import uniCountdown from '@/components/uni-countdown/uni-countdown.vue';
import redBag from '@/components/red-bag/index';
import { goods } from '@/config/mixins.js';
import { goBack } from '@/config/mixins.js';
export default {
	mixins: [goods],
	components: {
		mallplusCopyright,
		jshop,
		uniCountdown,
		redBag
	},
	data() {
		return {
		topmenu:{},
			imageUrl: '/static/image/share_image.png', //店铺分享图片
			pageData: [],
			pageTitle: [],
			pageCode: 'mobile_home', //页面布局编码
			pintuan: [], //拼团列表,
			redBagShow: false, //红包
			config: '', //配置信息
			userInfo: {}, // 用户信息
			kefupara: '', //客服传递资料
			id:0,
			copy: false,
			suTipStatus: false,
            shareUrl: '../../pagesU/user/jump'
		};
	},
	updated() {
		this.copy = true;
	},
	computed: {
		appTitle() {
			return this.pageTitle.pageName;
		},
		// 获取店铺联系人手机号
		shopMobile() {
			return this.$store.state.config.shop_mobile || 0;
		},
		suTip() {
			return this.suTipStatus;
		}
	},
	onLoad(e) {
	this.id=e.id;
		this.initData();
		if (this.pageTitle.pageName) {
			uni.setNavigationBarTitle({
				title:  this.pageTitle.pageName
			});
		}
	},
	onShow() {
		// #ifdef MP-WEIXIN
		this.userIsSubscription();
		// #endif
	},
	methods: {
		//领取红包
		handleGet() {},
		destroyed() {
			window.removeEventListener('scroll', this.handleScroll);
		},
		goSearch() {
			uni.navigateTo({
				url: './search'
			});
		},
		// 首页初始化获取数据
	async	initData() {
		let params={type:2,storeId:0};
	let res = await Api.apiCall('get',Api.index.diyDetail,params);
	//console.log(res)
			let items = JSON.parse(res.datas)

//console.log(items.currentTemplate)
			items.currentTemplate.forEach((item)=> {
                  if (item.id == 'topmenu') {
                   this.topmenu = item;
                    if (item.data[0] == undefined) {
                      var linkurl = '';
                    } else {
                      var linkurl = item.data[0].linkurl;
                      core.get('diypage/getInfo', {
                        dataurl: linkurl
                      }, function(ret) {
                        ////console.log(ret);
                        item.data[0].data = ret.goods.list;
                      });
                    }

                  }

                  if (item.id == 'seckillgroup') {
                    var data = {};
                    data.status = item.data.status;
                    data.endtime = item.data.endtime;
                    data.starttime = item.data.starttime;
                    $this.initSeckill(data);
                  }
                });
                this.pageData = items.currentTemplate;
                this.pageTitle =items.basicOption;
                setTimeout(() => {
                							this.showLoad = false;
                						}, 600);
			//获取首页配置

			var _this = this;
			if (this.$db.get('userToken')) {
				this.$api.userInfo({}, res => {
					if (res.status) {
						_this.userInfo = res.data;
						// #ifdef MP-WEIXIN
						//微信小程序打开客服时，传递用户信息
						var kefupara = {};
						kefupara.nickName = res.data.nickname;
						kefupara.tel = res.data.mobile;
						_this.kefupara = JSON.stringify(kefupara);
						// #endif
					}
				});
			}

			// #ifdef MP-WEIXIN
			this.userIsSubscription();
			// #endif
            
          //  this.getShareUrl();
		},
		//在线客服,只有手机号的，请自己替换为手机号
		showChat() {
			// #ifdef H5
			let _this = this;
			window._AIHECONG('ini', {
				entId: this.config.ent_id,
				button: false,
				appearance: {
					panelMobile: {
						tone: '#FF7159',
						sideMargin: 30,
						ratio: 'part',
						headHeight: 50
					}
				}
			});
			//传递客户信息
			window._AIHECONG('customer', {
				head: _this.userInfo.avatar,
				名称: _this.userInfo.nickname,
				手机: _this.userInfo.mobile
			});
			window._AIHECONG('showChat');
			// #endif

			// 客服页面
			// #ifdef APP-PLUS || APP-PLUS-NVUE
			this.$common.navigateTo('../customer_service/index');
			// #endif

			// 头条系客服
			// #ifdef MP-TOUTIAO
			if (this.shopMobile != 0) {
				let _this = this;
				tt.makePhoneCall({
					phoneNumber: this.shopMobile.toString(),
					success(res) {},
					fail(res) {}
				});
			} else {
				_this.$common.errorToShow('暂无设置客服电话');
			}
			// #endif
		},
		//前往订阅
		toSubscription() {
			this.$common.navigateTo('/pages/member/setting/subscription/index');
		},
		//查询用户订阅
		userIsSubscription() {
			let userToken = this.$db.get('userToken');
			if (userToken && userToken != '') {
				this.$api.subscriptionIsTip(res => {
					if (res.status) {
						if (res.data) {
							this.suTipStatus = true;
						} else {
							this.suTipStatus = false;
						}
					} else {
						this.suTipStatus = true;
					}
				});
			} else {
				this.suTipStatus = true;
			}
		},
		//关闭订阅
		toClose() {
			let userToken = this.$db.get('userToken');
			if (userToken && userToken != '') {
				this.$api.subscriptionCloseTip(res => {
					this.suTipStatus = false;
				});
			} else {
				this.suTipStatus = false;
			}
		},
        //获取分享URL
        getShareUrl() {
            let data = {
                client: 2,
                url: "../../pagesU/user/jump",
                type: 1,
                page: 1,
            };
            let userToken = this.$db.get('userToken');
            if (userToken && userToken != '') {
            	data['token'] = userToken;
            }
            this.$api.share(data, res => {
                this.shareUrl = res.data
            });
        }
	},
	onPullDownRefresh() {
		this.initData();
		uni.stopPullDownRefresh();
	},
	//分享
	onShareAppMessage() {
		return {
			title: this.$store.state.config.share_title,
			// #ifdef MP-ALIPAY
			desc: this.$store.state.config.share_desc,
			// #endif
			imageUrl: this.$store.state.config.share_image,
			path: this.shareUrl
		};
	},
	// #ifdef MP-WEIXIN || APP-PLUS || APP-PLUS-NVUE
	onPageScroll() {
		var _this = this;
		const query = uni.createSelectorQuery();
		query
			.select('.content >>> .search')
			.boundingClientRect(function(res) {
				if (res) {
					if (res.top < 0) {
						_this.$store.commit('searchFixed', true);
					} else {
						_this.$store.commit('searchFixed', false);
					}
				}
			})
			.exec();
	}
	//#endif
};
</script>

<style>
.cell-item {
	border: none;
}

.cell-ft-text {
	font-size: 22upx;
	color: #999;
}

.service {
	width: 80rpx;
	height: 80rpx;
	background-color: #fff;
	border-radius: 50%;
	position: fixed;
	right: 30rpx;
	bottom: 120rpx;
	display: flex;
	justify-content: center;
	align-items: center;
	box-shadow: 0 0 10rpx #ccc;
	padding: 0;
	z-index: 996;
}
.service .icon {
	width: 60rpx;
	height: 60rpx;
}
.subscription-notice {
	background-color: #ffffff;
	box-shadow: 0 2rpx 18rpx #eeeeee;
	position: relative;
	z-index: 99;
	height: 66rpx;
	line-height: 66rpx;
	padding: 0 20rpx;
	font-size: 28rpx;
	color: #333333;
	display: flex;
	justify-content: space-between;
	align-items: center;
}
.subscription-notice > view {
	display: flex;
	align-items: center;
}
.subscription-notice .icon {
	width: 32rpx;
	height: 32rpx;
	margin-right: 10rpx;
}
.subscription-notice-btn {
	color: #4285f4;
}
.subscription-notice-btn-close {
	color: #888888;
	padding-left: 10px;
	font-size: 30rpx;
}
</style>
